package com.projects.android.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.projects.android.R;
import com.projects.android.bus.FoodBUS;
import com.projects.android.dto.OrderDetailDTO;

public class ManageOrderDetailsAdapter extends ArrayAdapter<OrderDetailDTO> {
	private LayoutInflater mInflater;

	public ManageOrderDetailsAdapter(Context context, int resource, int textViewResourceId,
			List<OrderDetailDTO> objects) {
		super(context, resource, textViewResourceId, objects);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ManageOrderDetailsViewHolder holder = null;
		TextView food = null;
		TextView quantity = null;
		TextView price = null;
		OrderDetailDTO rowData = getItem(position);

		if (null == convertView) {
			convertView = mInflater.inflate(R.layout.orderdetailitem, null);
			holder = new ManageOrderDetailsViewHolder(convertView);
			convertView.setTag(holder);
		}

		holder = (ManageOrderDetailsViewHolder) convertView.getTag();

		food = holder.getFood();
		food.setText(String.valueOf(FoodBUS.selectByID(rowData.getIDFood())));
		
		quantity = holder.getQuantity();
		quantity.setText(String.valueOf(rowData.getQuantity()));
		
		price = holder.getPrice();
		price.setText(String.valueOf(rowData.getPrice()));
		
		return convertView;
	}
}
